<template>
	<view class="ys">
		<view class="info">

			<view class="infoli">
				<view class="left">
					收款码
				</view>
				<view class="right">
					<image v-if="aliImg" :src="domain+aliImg || '/static/sc.png'" @click="uploadImg('ali')"
						mode="widthFix">
					</image>
					<image v-else src="/static/sc.png" @click="uploadImg('ali')" mode="widthFix">
					</image>
				</view>
			</view>
		</view>
		<button @click="setInfo">确认修改</button>
	</view>
</template>

<script>
	import {
		ShopImg,
		showShopImg
	} from "@/api/shop.js"
	export default {
		data() {
			return {
				domain: this.$config.websiteUrl,
				aliname: '',
				alino: '',
				aliImg: '',
				wxImg: '',
				ali_show: '',
				wx_show: '',
				bankname: '',
				bankno: '',
				bankzh: '',
				bank_user: ''
			}
		},
		onLoad() {
			this.showShopImg()
		},
		methods: {
			setInfo() {
				ShopImg({
					img: this.ali_show
				}).then(res => {
					uni.$showMsg(res.message)
					if (res.status == 1) {
						setTimeout(() => {
							uni.navigateBack()
						}, 500)
					}
				})
			},
			showShopImg() {
				showShopImg().then(res => {
					if (res.status == 1) {
						this.aliImg = res.data
					} else {
						uni.$showMsg(res.message)
					}
				})
			},
			seeimg(url) {
				let urls = [url]
				uni.previewImage({
					urls
				})
			},
			uploadImg(type) {
				var that = this
				uni.chooseImage({
					sourceType: ['album', 'camera'], //从相册选择
					count: 1,
					success: (res) => {
						let igmFile = res.tempFilePaths;
						uni.showLoading({
							mask: true,
							title: '加载中'
						})
						for (let i = 0; i < igmFile.length; i++) {
							uni.uploadFile({
								url: that.$config.requestUrl +
									'/Index/forUpload',
								header: {
									'token': uni.getStorageSync('token')
								},
								formData: {
									accept: 'image',
								},
								filePath: igmFile[i],
								name: 'image',
								success: (res) => {
									uni.hideLoading()
									let imgRes = JSON.parse(res.data); //微信和头条支持
									if (imgRes.status == 1) {
										let imgData = imgRes.data
										let url = imgData
										console.log(imgRes);
										if (type == 'ali') {
											this.aliImg = url
											this.ali_show = url
										} else if (type == 'wx') {
											this.wxImg = url
											this.wx_show = url
										}
										console.log();
									} else {
										uni.showToast({
											title: res.message,
											icon: "none"
										})
										return
									}
								},
								fail(err) {
									uni.hideLoading()
								}
							})
						}
					},
				});
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #f2f2f2;
		padding-top: 15px;
		padding-bottom: 10px;
	}

	button {
		width: 96%;
		height: 41px;
		border-radius: 20px;
		line-height: 41px;
		text-align: center;
		font-size: 15px;
		color: #fff;
		background: linear-gradient(0deg, #2573e8, #6ba9fc);
		margin: 0 auto;
		margin-top: 20px;
	}

	.info {
		width: 96%;
		margin: 0px auto;
		background: #fff;
		border-radius: 8px;
		box-sizing: border-box;
		padding: 10px;



		.infoli {
			display: flex;
			font-size: 14px;
			padding: 18px 0;

			.left {
				width: 100px;
				font-size: 15px;
				font-weight: bold;
				margin-right: 10px;
			}

			.right {
				flex: 1;

				image {
					width: 40%
				}

				input {
					font-size: 14px;
				}
			}
		}
	}
</style>